<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/admin/commons/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>后台管理</title>
    <script type="text/javascript">
        $(function(){
            $("#shezhi").addClass("active");
            $("#shezhi").find("ul li").eq(1).addClass("active");
        })
    </script>
</head>
<body>
    <div class="admin">
         <form id="form" method="post" action="teacher!delete.action">
            <div class="panel admin-panel">
                <div class="panel-head">
                    <strong><s:property value="desc"/>校区列表</strong>

                </div>
                <div class="padding border-bottom">
                    <a style="cursor: pointer" onclick="addClassify();"><input type="button" class="button button-small border-green" value="添加分类" /></a>
                </div>

                <table id="tableId" class="table table-hover">
                    <tr><th width="120">校区名称</th><th width="120">校区域名</th><th width="200">操作</th></tr>
                    <s:if test="xiaoquList!=null&&xiaoquList.size()>0">
                       <s:iterator value="xiaoquList">
                        <tr>
                            <td>
                                <input style="border:1px solid #F5F5F5;" name="name" value="<s:property value="name"/>"/>
                            </td>
                            <td>
                                <input style="border:1px solid #F5F5F5;" name="webUrl" value="<s:property value="webUrl"/>"/>
                            </td>
                            <td><a class="button border-blue button-little" style="cursor: pointer" onclick="saveClassify(this,<s:property value='id'/>)" >保存</a>
                                <a class="button border-red button-little" href="peizhi!deleteXq.action?xiaoqu.id=<s:property value="id"/>"
                                   onclick="{if (confirm('确认删除?')) {return true;}return false;};">删除</a></td>
                        </tr>
                        </s:iterator>
                    </s:if>
                    <s:else>
                        <td colspan="4" align="center">暂无数据</td>
                    </s:else>

                </table>
            </div>
         </form>

    </div>

    <script type="text/javascript">
        //添加一行
        function addClassify(){
            $('#tableId').append("<tr><td><input style=\"border:1px solid #F5F5F5;\" name=\"name\" value=\"\"/></td>" +
                "<td><input style=\"border:1px solid #F5F5F5;\" name=\"webUrl\" value=\"\"/></td>" +
                "<td><a class=\"button border-blue button-little\" style=\"cursor: pointer\" onclick=\"saveClassify(this,'')\" >保存</a> </td></tr>");
        }
        //保存分类
        function saveClassify(obj,id){
            var name = $(obj).parents('tr').find('input[name="name"]').val();
            var webUrl = $(obj).parents('tr').find('input[name="webUrl"]').val();
            if(webUrl!=""&&name!=""){
                $.ajax({
                    'url':'peizhi!save.action',
                    'type':'post',
                    'data':{'xiaoqu.webUrl':webUrl,'xiaoqu.name':name,'xiaoqu.id':id},
                    'dataType':'json',
                    'success':function(data){
                        alertDiv("保存成功！");
                        window.location.reload();
                    },
                    'error':function(){
                        alertDiv("请求失败！");
                    }
                });
            }else{
                alert("请填写相关参数");
            }
        }
    </script>
</body>
</html>
